<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计数器</title>
    <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script crossorigin src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
    const root = ReactDOM.createRoot(document.getElementById('root'))

    class App extends React.Component {
        constructor(props) {
            super();
            this.state = {
                count: 0
            }
            this.inc = this.inc.bind(this);
            this.dec = this.dec.bind(this);
        }

        inc = function () {
            this.setState({
                count: this.state.count + 1
            })
        };

        dec = function () {
            this.setState({
                count: this.state.count - 1
            })
        };
        render() {
            const { count } = this.state;
            return (
                <div>
                    <h1>计数器</h1>
                    <h2>计数：{count}</h2>
                    <button onClick={this.inc}>+1</button>
                    <span> </span>
                    <button onClick={this.dec}>-1</button>
                </div>
            )
        }
    }
    root.render(<App />);
</script>
</body>
</html>